package com.xiaoshuidi.cloud.framework.pay.core.client.impl.tongshangyun;

import com.xiaoshuidi.cloud.framework.pay.core.client.PayClientConfig;
import lombok.Data;

import javax.validation.ConstraintViolation;
import javax.validation.Validator;
import javax.validation.constraints.NotEmpty;
import java.util.Random;
import java.util.Set;

/**
 * 属 性主要来自 {@link com.allinpay.sdk.bean.OpenConfig} 的必要属性
 */
@Data
public class TongshangyunClientConfig implements PayClientConfig {
//    @NotEmpty(message = "cusid不能为空")
//    private String cusid;
//    /**
//     * 集团商务号
//     */
//    private String orgid;


    @NotEmpty(message = "账户集编号不能为空")
    private String accountSetNo;

//    /**
//     * 商户SM2私钥
//     */
//    @NotEmpty(message = "商户SM2私钥不能为空")
//    private String sm2PrivateKey;
//
//    /**
//     * 通联SM2公钥
//     */
//    @NotEmpty(message = "通联SM2公钥不能为空")
//    private String sm2PublicKey;

    @NotEmpty(message = "url不能为空")
    private String url;

    @NotEmpty(message = "收银宝appId不能为空")
    private String allinpayAppid;

    @NotEmpty(message = "appId不能为空")
    private String appId;

    @NotEmpty(message = "secretKey不能为空")
    private String secretKey;

    @NotEmpty(message = "应用私钥证书")
    private String certPath;

    @NotEmpty(message = "应用私钥证书密码不能为空")
    private String certPwd;

    @NotEmpty(message = "开放平台公钥证书")
    private String tlCertPath;

    @Override
    public Set<ConstraintViolation<PayClientConfig>> verifyParam(Validator validator) {
        return validator.validate(this);
    }

    public static String getValidatecode(int n) {
        Random random = new Random();
        String sRand = "";
        n = n == 0 ? 4 : n;// default 4
        for (int i = 0; i < n; i++) {
            String rand = String.valueOf(random.nextInt(10));
            sRand += rand;
        }
        return sRand;
    }
}
